package org.haifi.game.util;

import org.apache.commons.codec.binary.Base64;

/**
 * base64 编码解码工具类
 * 
 * @author joycube2
 * 
 */
public class Base64Util {
	/**
	 * 对str进行base64加密
	 * 
	 * @param str
	 * @return
	 */
	public static String encode(String str) {
		try {
			return Base64.encodeBase64String(str.getBytes("UTF-8"));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * 对str进行base64解密
	 * 
	 * @param str
	 * @return
	 */
	public static String decode(String str) {
		try {
			return new String(Base64.decodeBase64(str), "UTF-8");
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
